package com.industry.framework.common;

import lombok.Data;

/**
 * 通用结果返回值
 *
 * @param <T>
 */
@Data
public class Result<T> {
    int code;
    String message;
    T data;

    public Result() {
    }

    public Result(int code, String message, T data) {
        this();
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getDesc(), data);
    }

    public static <T> Result<T> success(ResultCodeEnum resultCodeEnum, T data) {
        return new Result<>(resultCodeEnum.getCode(), resultCodeEnum.getDesc(), data);
    }

    public static <T> Result<T> fail(int code, String message) {
        return new Result<>(code, message, null);
    }

    public static <T> Result<T> fail(ResultCodeEnum resultCodeEnum) {
        return new Result<>(resultCodeEnum.getCode(), resultCodeEnum.getDesc(), null);
    }

    public static <T> Result<T> fail(String message) {
        return fail(ResultCodeEnum.FAIL.getCode(), message);
    }

    public static <T> Result<T> fail() {
        return fail(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getDesc());
    }
}